package com.bupt.ilink.controller;

import com.bupt.ilink.entity.FileTranscriptionTaskResponse;
import com.bupt.ilink.mapper.FileTranscriptionMapper;
import com.bupt.ilink.service.FileTranscriptionService;
import com.bupt.ilink.utils.FileTranscriptionParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bupt.ilink.utils.R;
import java.util.List;

@RestController
@RequestMapping("/fileTrans")
public class FileTranscriptionController {

    @Autowired
    private FileTranscriptionService fileTransService;

    @Autowired
    private FileTranscriptionMapper fileTransMapper;

    @PostMapping("/createTask")
    public R test(@RequestBody FileTranscriptionParameters parameters){
        String fileUrl = parameters.getFile_url();
        boolean diarization_enabled = parameters.isDiarization_enabled();
        int speaker_count = parameters.getSpeaker_count();
        boolean translation_enabled = parameters.isTranslation_enabled();
        List<String> language= parameters.getLanguage();

        FileTranscriptionTaskResponse result = fileTransService.createFileTransTask(
                                                                    fileUrl,
                                                                    diarization_enabled,
                                                                    speaker_count,translation_enabled,
                                                                    language);
        return R.ok(result);
    }

    @GetMapping("/getInfo")
    public R getResult(@RequestParam String taskId, @RequestParam String sourcePath){
        FileTranscriptionTaskResponse result = fileTransService.getFileTransInfo (taskId, sourcePath);
        if(result != null){
            return R.ok(result);
        }else{
            return R.failure("文件未找到"+taskId);
        }
    }

}